<?PHP

class gallery extends content
{
   var $category_parent;
	var $gallery_images;
	var $galleries;
	var $items;
	var $current_gallery;
	
	function gallery()
	{
		mp('loading gallery');
	}
	
	
	function digest()
	{
		global $conf;

		$this->where['id']=$conf->qm[1];
		$this->get_content();
		$this->current_gallery = $this->piece;
		
		$category=new content_category();
		$category->where['id']=$this->piece['category'];
		$category->get_category();
		mp('got category');
		

		if($category->piece['type']=='video' && $category->piece['status']=='enabled')
		{
			mp('enabled video');
			$serial=unserialize($category->piece['serial']);
			$conf->style['masthead']=$category->piece['name'];
			$conf->style['background'].='background-image:url('.ap($serial["serial_style_background_image"]).');';
			$conf->style['background'].='background-color:#'.$serial["serial_style_background_color"].';';
			$conf->style['custom-masthead']=='color:#'.$serial["serial_style_masthead_color"].';';
			mp(ap($category->piece['image']));
				
				if(!empty($category->piece['image']))
				{
					$conf->style['masthead']='<img src="'.ap($category->piece['image']).'"/>';
				}
			
		}
		
			$this->display=TRUE;
			$this->category_parent = $category->piece;
			$conf->page_render='assets/pages/gallery.php';

	}
	function get_gallery_images()
	{
		global $conf;
		
		$image_gallery=new media();
		$image_gallery->where['content']=$conf->qm[1];
		$image_gallery->get_gallery_images();
		$this->gallery_images = $image_gallery->data;
		
	}
	
	function get_galleries()
	{
		global $conf;
		mp('grab Galleries');
		unset($this->where);
		$this->where['category']=$this->category_parent['id'];
		$this->where['type']='gallery';
		$this->get_content();
		$this->galleries=$this->data;

	}
	
	function get_items()
	{
		mp('grab items');
		$this->items=$this->get_category_items($this->category_parent['id']);
	}
	function get_latest_video()
	{
		$reverse_items = array_reverse($this->items);
		 $today= date("Y-m-d");
	     foreach($reverse_items as $x){
			$start = substr($x['start'],0,10);
			if($x['type']== 'video' && $today == $start){
				$this->latest_video = $x;
				break;
		    }
		 }
	}
	
}	
	
	

?>